﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TY.Utilities
{
    /// <summary>
    /// 日志格式器
    /// </summary>
    public class LogFormat
    {
        /// <summary>
        /// 生成错误
        /// </summary>
        /// <param name="logMessage">对象</param>
        /// <returns></returns>
        public string ErrorFormat(LogMessage logMessage)
        {
            StringBuilder strInfo = new StringBuilder("\r\n");
            strInfo.Append("1. 错误: >> 操作时间: " + logMessage.OperationTime + "   操作人: " + logMessage.UserName + " \r\n");
            strInfo.Append("2. 类名: " + logMessage.Class + " \r\n");
            strInfo.Append("3. 内容: " + logMessage.Content + "\r\n");
            strInfo.Append("-----------------------------------------------------------------------------------------------------------------------------\r\n");
            return strInfo.ToString();
        }
        /// <summary>
        /// 生成警告
        /// </summary>
        /// <param name="logMessage">对象</param>
        /// <returns></returns>
        public string WarnFormat(LogMessage logMessage)
        {
            StringBuilder strInfo = new StringBuilder("\r\n");
            strInfo.Append("1. 警告: >> 操作时间: " + logMessage.OperationTime + "   操作人: " + logMessage.UserName + " \r\n");
            strInfo.Append("2. 类名: " + logMessage.Class + " \r\n");
            strInfo.Append("3. 内容: " + logMessage.Content + "\r\n");
            strInfo.Append("-----------------------------------------------------------------------------------------------------------------------------\r\n");
            return strInfo.ToString();
        }
        /// <summary>
        /// 生成信息
        /// </summary>
        /// <param name="logMessage">对象</param>
        /// <returns></returns>
        public string InfoFormat(LogMessage logMessage)
        {
            StringBuilder strInfo = new StringBuilder("\r\n");
            strInfo.Append("1. 信息: >> 操作时间: " + logMessage.OperationTime + "   操作人: " + logMessage.UserName + " \r\n");
            strInfo.Append("2. 类名: " + logMessage.Class + " \r\n");
            strInfo.Append("3. 内容: " + logMessage.Content + "\r\n");
            strInfo.Append("-----------------------------------------------------------------------------------------------------------------------------\r\n");
            return strInfo.ToString();
        }
        /// <summary>
        /// 生成调试
        /// </summary>
        /// <param name="logMessage">对象</param>
        /// <returns></returns>
        public string DebugFormat(LogMessage logMessage)
        {
            StringBuilder strInfo = new StringBuilder("\r\n");
            strInfo.Append("1. 调试: >> 操作时间: " + logMessage.OperationTime + "   操作人: " + logMessage.UserName + " \r\n");
            strInfo.Append("2. 类名: " + logMessage.Class + " \r\n");
            strInfo.Append("3. 内容: " + logMessage.Content + "\r\n");
            strInfo.Append("-----------------------------------------------------------------------------------------------------------------------------\r\n");
            return strInfo.ToString();
        }
        /// <summary>
        /// 生成异常信息
        /// </summary>
        /// <param name="logMessage">对象</param>
        /// <returns></returns>
        public string ExceptionFormat(LogMessage logMessage)
        {
            StringBuilder strInfo = new StringBuilder("\r\n");
            strInfo.Append("1. 异常: >> 时间: " + logMessage.OperationTime + " \r\n");
            strInfo.Append("2. 类名: " + logMessage.Class + " \r\n");
            strInfo.Append("3. 信息: " + logMessage.ExceptionInfo + "\r\n");
            //strInfo.Append("4. 来源: " + logMessage.ExceptionSource + "\r\n");
            strInfo.Append("4. 详情: " + logMessage.ExceptionRemark + "\r\n");
            strInfo.Append("-----------------------------------------------------------------------------------------------------------------------------\r\n");
            return strInfo.ToString();
        }
    }
}
